'''
Created on Dec 16, 2010

@author: mwicat
'''

import logging
logger = logging.getLogger(__name__)


from sniffylib.core import application

from sniffylib.rpc import core as rpc_core

def run(config):
    app = application.App(config)
    app.launch()
    sh = config.shell
    while True:
        cmdln = raw_input('$ ')
        name, params = rpc_core.parse_cmdln(cmdln)
        cmd = rpc_core.SniffyCmd('User', name, params)
        if not cmd:
            break
        try:
            r = sh.interpret(cmd)
            if r is not None:
                logger.debug(r)
        except rpc_core.CmdInternalException, e:
            logger.debug('error %s' % e.internal)
        except rpc_core.CmdException, e:
            logger.debug('error %s' % e)
